package priv.hxm.serve;

import io.netty.channel.Channel;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class SessionContext {

	private static Map<Channel, ChinaUser> map=new HashMap<>();

	public static void remove(Channel channel) {
		map.remove(channel);
	}

	public static void put(Channel channel) {
		map.put(channel, null);
	}

	public static void put(Channel channel, ChinaUser msg) {
		ChinaUser chinaUser = map.get(channel);
		if(chinaUser==null){
			map.put(channel, msg);
		}
	}

	public static void Each(SerssionHandler serssionHandler) {
		
		Set<Entry<Channel, ChinaUser>> entrySet = map.entrySet();
		Iterator<Entry<Channel, ChinaUser>> iterator = entrySet.iterator();
		while (iterator.hasNext()) {
			Entry<Channel, ChinaUser> next = iterator.next();
			serssionHandler.handlerSession(next.getKey(),next.getValue());
		}
	}
	
}
